<template>
  <div>
    <el-form :inline="true">
      <el-form-item label="条件查询">
        <el-input v-model="keyword" placeholder="手机/身份证号码/id"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" plain @click="clearInput">清除</el-button>
      </el-form-item>
    </el-form>
    <el-table border :data="data" style="width: 100%">
      <el-table-column
        align="center"
        label="序号"
        width="80"
      >
        <template slot-scope="{$index}">
           {{ (page - 1) * limit + $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column prop="name" label="姓名"></el-table-column>
      <el-table-column prop="mobile" label="手机"></el-table-column>
      <el-table-column prop="idCard" width="180" label="身份证"></el-table-column>
      <el-table-column label="性别">
        <template slot-scope="{ row }">
          {{ row.sex == 1 ? '男' : '女' }}
        </template>
      </el-table-column>
      <el-table-column label="年龄" prop="age"></el-table-column>
      <el-table-column label="婚否">
        <template slot-scope="{ row }">
          {{ row.marry ? '是' : '否' }}
        </template>
      </el-table-column>
      <el-table-column label="转态">
        <template slot-scope="{ row }">
          <el-tag v-if="row.status == 0" type="warning">未认证</el-tag>
          <el-tag v-if="row.status == 1" type="warning">认证中</el-tag>
          <el-tag v-if="row.status == 2" type="success">认证通过</el-tag>
          <el-tag v-if="row.status == -1" type="danger">认证失败</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="申请时间"  width="180"></el-table-column>
      <el-table-column label="操作" align="center" >
        <template slot-scope="{ row }">
          
          <router-link  :to="`/core/borrow/detail/${row.id}`">
            <el-button v-if="row.status===0||row.status===1" type="primary" size="small" >审批</el-button>
            <el-button v-else type="primary" size="small">详情</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-sizes="[3, 5, 10, 50]"
      :page-size="limit"
      align="center"
      layout="prev, pager, next, jumper,->, sizes,total"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: [],
      page: 1,
      limit: 3,
      keyword: null,
      total:100
    }
  },
  methods: {
    handleSizeChange(size){
      this.limit = size;
      this.fetchData()
    },
    handleCurrentChange(page){
      this.page = page
      this.fetchData(this.page)
    },

    async fetchData(page = 1) {
      this.page = page
      const result = await this.$API.borrow.getPageList(
        this.page,
        this.limit,
        this.keyword
      )
      if (result.code == 200) {
        this.data = result.data.pageModel.records
      }
    },
    onSubmit() {
      this.fetchData()
    },
    clearInput() {
      this.keyword = null   
      this.fetchData()
    },
  },
  mounted() {
    this.fetchData()
  },
}
</script>

<style></style>
